package com.abbas.abchat.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.abbas.abchat.AbChatApplication;
import com.abbas.abchat.R;
import com.abbas.abchat.utils.SpUtils;

@SuppressLint("CustomSplashScreen")
public class SplashActivity extends BaseActivity {

    private Button btLogin;
    private Button btRegister;

    @Override
    protected void init() {
        AbChatApplication.putActivityTask(this);

        if (SpUtils.config(this,SpUtils.LOGIN_ACCOUNT).isLogin()) {
            //TODO auto login account
            SpUtils.config(this,SpUtils.LOGIN_ACCOUNT).autoLogin(this);
            //TODO start home activity
            migrateTo(HomeActivity.class);
            //TODO finish this
            finishThis();
        }

        btLogin = (Button) findViewById(R.id.bt_login);
        btRegister = (Button) findViewById(R.id.bt_register);
    }

    @Override
    protected void initEvent() {
        btRegister.setOnClickListener(v -> migrateTo(RegisterActivity.class));

        btLogin.setOnClickListener(v -> {
            migrateTo(LoginActivity.class);
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        AbChatApplication.finishActivity(this.getClass().getSimpleName());
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    }
}